<script>
    if ("serviceWorker" in navigator) {
        if (navigator.serviceWorker.controller) {
            console.log("An active service worker found, no need to register");
        } else {
            // Register the service worker
            navigator.serviceWorker
            .register("{{ "/sw.js" | prepend: site.baseurl }}", {
                scope: "{{ "/" | prepend: site.baseurl }}"
            })
            .then(function (reg) {
                console.log("Service worker has been registered for scope: " + reg.scope);
            });
        }
    }

// 检测浏览器是否支持SW
// if(navigator.serviceWorker != null){
//     navigator.serviceWorker.register("{{ "/sw.js" | prepend: site.baseurl }}")
//         .then(function(registartion){
//             console.log('支持sw:',registartion.scope)
//         })
// } else {
//     console.log('不支持sw')
// }
</script>